import axios from 'axios';
import Config from '@/utils/config';
import { EventBus } from './EventBus.js'

export default {
	install(Vue) {
		let videos = [];
		
		/**
		 * 返回/utils/config里的配置信息。
		 * @return {}
		 */
		Vue.prototype.defaultConfig = Config

		/**
		 * 获取头像pic
		 * @param {acctUid} 央视屏号id
		 * @return {String} 返回url 
		 */
		Vue.prototype.getAvatar = function(acctUid, callback) {
			axios
				.get('https://h5access.yangshipin.cn/web/cp_homepagehtml_feed?vappid=59306155&vsecret=b42702bf7309a179d102f3d51b1add2fda0bc7ada64cb801&raw=1&cpid='+acctUid)
				.then((res) => {
					if (callback) callback(res["data"]["data"]["cp_avatar"]);
				})
				.catch((e) => {
					console.log(e)
				})
		};

		/**
		 * 获取致敬数
		 * @return {Number} 返回数量 
		 */
		Vue.prototype.getRespect = function(callback) {
			let timestamp = parseInt(new Date().getTime() / 1000 / 60)
			axios
				.get("https://sapi.yangshipin.cn/assets/x/b0000y4gi9g/rank/like.json?v=26729865&t="+timestamp)
				.then((res) => {
					if (callback) callback(res["data"]["list"][0]["likeNums"]);
				})
				.catch((e) => {
					console.log(e)
				})
		};

		/**
		 * 获取鱼、探索成就配置文件
		 * @return {Array} 返回个数 
		 */
		Vue.prototype.getSourceConfig = function(callback) {
			let timestamp = parseInt(new Date().getTime() / 1000 / 60)
			axios
				.get("https://s.yangshipin.cn/api/x/wuji/appid/1000746/appkey/70d67f80bf714666a9a695d4a66a9e74/list.json?t="+timestamp)
				.then((res) => {
					if (callback) callback(res["data"]);
				})
				.catch((e) => {
					console.log(e)
				})
		};		
	}
};
